package com.atguigu.test;

import lombok.extern.slf4j.Slf4j;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

@Slf4j
public class SpringELDemo {

    //占位符替换
    public static void main(String[] args) {
        log.info("log:{}", "abcd");
        System.out.println();


        //spring.format占位符替换
        String result = String.format("%s,java", "尚硅谷 study");
        System.out.println(result);
        System.out.println();

        //springELExpress表达式，#后面的内容可以被具体值替换
        String var = "#userid";


        SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
        Expression expression = spelExpressionParser.parseExpression(var);

        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setVariable("userid","1253");

        String s = expression.getValue(context).toString();
        System.out.println(s);
    }
}
